---
sidebar_position: 5
description: Learn about tree-shaking in Microsoft DeviceScript, how to use the
  ds.keep() function, and potential improvements in future releases.
keywords:
  - tree-shaking
  - Microsoft DeviceScript
  - ds.keep
  - index operator
  - compiler warnings
---
# Tree-shaking

Classes and/or methods in classes can be marked with `@devsWhenUsed` JSDoc attribute.
This will cause them to be omitted from compilation unless they are used.
In such case, care needs to be taken when using index operator (`obj[some_expression]`)
or accessing properties through `any` type.
You can use `ds.keep()` function to make sure methods are included.

```ts
/**
 * Foooooo!
 * 
 * @devsWhenUsed
 */
class Foo {
    bar() {}
}
function callBar(v: any) {
    v["bar"]()
}
callBar(new Foo())

// can be called anywhere from the reachable code
ds.keep(Foo.prototype.bar)
```

The `@devsWhenUsed` attribute is implicit when methods are defined through
prototype assignments.

We may improve compiler warnings about such cases in future.

See [discussion](https://github.com/microsoft/devicescript/discussions/36).
